package com.latefly.skewwork

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.latefly.skewwork.ui.layout.LayoutViewModel
import com.latefly.skewwork.ui.page.AppNavigation
import com.latefly.skewwork.ui.page.PageViewModels
import com.latefly.skewwork.ui.page.tools.calculator.CalculatorViewModel
import com.latefly.skewwork.ui.page.tools.todo.TodoViewModel
import com.latefly.skewwork.ui.theme.SkewWorkTheme
import com.latefly.skewwork.utils.PermissionUtils

class MainActivity : ComponentActivity() {

    @ExperimentalPermissionsApi
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        FileUtils.writeStringInternalStorage(this, "test.txt", "aaaaaaaaaaaaaaaaaa")
        PermissionUtils.checkBlePermission(this)

        //创建数据库测试
//        val db = createDataBase(this, "skew_work")
//        db.userRepository().insert(User(1, "John", 25))
//        val users = db.userRepository().getAll()

        setContent {
            SkewWorkTheme {
                val todoViewModel by viewModels<TodoViewModel>()
                val layoutViewModel by viewModels<LayoutViewModel>()
                val calculatorViewModel = viewModel<CalculatorViewModel>()

                Surface(
                    modifier = Modifier
                        .wrapContentHeight()
                        .wrapContentWidth(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    AppNavigation(
                        PageViewModels(
                            layoutViewModel,
                            todoViewModel,
                            calculatorViewModel
                        )
                    )
                }
            }
        }
    }
}
